home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / Navigation Services SDK / Examples / StExample / HelloWorld.cp next >
Encoding:
Text File  |  1999-06-16  |  3.3 KB  |  111 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        HelloWorld.cp
  3.  
  4.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. /*    
  9.  *    StExample
  10.  *
  11.  *    A set of useful utility classes for using Navigation Services.
  12.  *    Requires building with CodeWarrior Pro2.
  13.  *
  14.  *    Sample to show StNavGetFile and StNavPutFile classes
  15.  *    To Compile it: 
  16.  *        1 - Place an alias to Navigation.h (from SDK) in your project folder.
  17.  *        2 - Include NavigationLib (from SDK) in your project.
  18.  *    To Run it:
  19.  *        1 - Place an alias to Navigation library (from SDK) in same folder as target output.    
  20.  */
  21.  
  22. //    
  23. //    You may incorporate this sample code into your applications
  24. //    without restriction. This sample code has been provided "AS
  25. //    IS" and the responsibility for its operation is 100% yours.
  26. //    You are not permitted to redistribute the source as "Apple
  27. //    sample code" after having made changes. If you're going to
  28. //    re-distribute the source, we require that you make it clear
  29. //    in the source that the code was descended from Apple sample
  30. //    code, but that you've made changes.
  31. //    
  32.     
  33. #include <iostream>
  34. #include "StNavServices.h"
  35.  
  36. #ifndef __NAVIGATION__
  37. #include "Navigation.h"
  38. #endif
  39.  
  40. #ifndef _H_UAppleEventsMgr
  41. #include <UAppleEventsMgr.h>
  42. #endif
  43.  
  44. pascal OSErr myOpen ( FSSpecPtr spec );
  45. pascal void myEvent ( NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD );
  46.  
  47. //    demonstrates open call for StNavGetFile
  48. pascal OSErr myOpen ( FSSpecPtr spec )    
  49. {
  50.     cout << "Open " << p2cstr ( spec->name ) << endl;
  51.     return noErr;
  52. }
  53. RoutineDescriptor rdopen = BUILD_ROUTINE_DESCRIPTOR ( StNavGetFileOpenProcInfo, myOpen );
  54.  
  55. //    demonstrates how to handle event callbacks from Navigation Services
  56. pascal void myEvent ( NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD )
  57. {
  58.     long ud = callBackUD;
  59.     if ( callBackSelector == kNavCBEvent && callBackParms->eventData.event->what == updateEvt )
  60.         cout << "Update" << endl;
  61.     
  62. }
  63. RoutineDescriptor rdevt = BUILD_ROUTINE_DESCRIPTOR ( uppNavEventProcInfo, myEvent );
  64.  
  65. int main()
  66. {
  67.     cout << "StNavServices:\nA 'stack-based' object example for using Navigation Services.\n" << endl << endl;
  68.     
  69.     OSErr err;
  70.     FSSpec spec;
  71.     
  72. //    way simple way to get a spec to a single file    
  73.     StNavGetFile gf( &err, &spec );
  74.  
  75. //    more options for getting files
  76.     FSSpecArrayPtr specs;
  77.     NavReplyRecord navreply;    //    use OUR reply record
  78.  
  79.     //    use this type list instead of application's open resourece
  80.     NavTypeListHandle tlh = StNavGetFile::MakeTypeList ( 'ttxt', 4, 'ttro', 'PICT', 'TEXT', 'MooV' );
  81.     long numspecs;
  82.     
  83.     StNavGetFile gf1( &err, &specs, &numspecs, &rdopen, &navreply, false, true, &rdevt, nil, nil, tlh, 0xaabbccdd  );
  84.  
  85.     if ( err == noErr )
  86.         NavDisposeReply ( &navreply );    //    if we supply it, we dispose of it
  87.  
  88.     DisposeHandle ( (Handle) tlh );
  89.     
  90. //    use StNavPutFile within a block which closes the file
  91.     {
  92.         FSSpec pspec;
  93.         NavReplyRecord preply;
  94.         StNavPutFile pf( &err, 'TEXT', 'ttxt', &pspec, &preply, &rdevt );
  95.         if ( err == noErr )
  96.         {
  97.             if ( preply.replacing )
  98.                 FSpDelete(&pspec);
  99.             FSpCreate(&pspec, 'ttxt', 'TEXT', smSystemScript);
  100.             short refNum;
  101.             FSpOpenDF(&pspec, fsWrPerm, &refNum);
  102.             long count = sizeof    (        "Smile :-)");
  103.             FSWrite(refNum, &count,     "Smile :-)");
  104.             FSClose(refNum);
  105.         }
  106.     }    //    StNavPutFile destructor will finish things up
  107.         
  108.     return 0;
  109. }
  110.  
  111.